package edu.hubu.talentmanagementsystem.auth;

import com.google.common.base.Objects;
import edu.hubu.talentmanagementsystem.common.RoleType;

import java.util.List;
import java.util.StringJoiner;

/**
 * @author moonlan
 * date 2021/2/9 下午4:13
 *
 * Payload类，其中保存了用户名，角色名，权限
 */
@SuppressWarnings(value = "unused")
public class Payload {
    private String userName;
    private RoleType roleName;
    private List<JwtGrantedAuthority> authorities;

    public String getUserName() {
        return userName;
    }

    public Payload setUserName(String userName) {
        this.userName = userName;
        return this;
    }

    public RoleType getRoleName() {
        return roleName;
    }

    public Payload setRoleName(RoleType roleName) {
        this.roleName = roleName;
        return this;
    }

    public List<JwtGrantedAuthority> getAuthorities() {
        return authorities;
    }

    public Payload setAuthorities(List<JwtGrantedAuthority> authorities) {
        this.authorities = authorities;
        return this;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (!(o instanceof Payload))
            return false;
        Payload payload = (Payload) o;
        return Objects.equal(getUserName(), payload.getUserName()) && Objects.equal(getRoleName(),
                payload.getRoleName()) && Objects.equal(getAuthorities(), payload.getAuthorities());
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(getUserName(), getRoleName(), getAuthorities());
    }

    @Override
    public String toString() {
        return new StringJoiner(", ", Payload.class.getSimpleName() + "[", "]")
                .add("userName='" + userName + "'")
                .add("roleName='" + roleName + "'")
                .add("authorities=" + authorities)
                .toString();
    }
}
